package com.lds.offer.demo;

/**
 * @description: 剑指 Offer 62. 圆圈中最后剩下的数字
 * @author: lds
 * @create: 2022-10-06 11:21
 **/
public class Offer_62_圆圈剩下数字{

    //https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/

    /***
     * 递归
     *
     */

    public static void main(String[] args) {
        int f = f(5, 3);
        System.out.println(f);
    }

    /**
     * @param n 数组长度
     * @param m 删除位数
     * @return 剩余数下标
     */
    public static int f(int n, int m) {
        if (n ==1) {
            return 0;
        }
        int index = f(n-1,m);
        return (m+index)%n;
    }
}
